import Vue from 'vue'
import Router from 'vue-router'
import homepage from '@/components/homepage'
// import product from '@/components/product'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/redirect',
    // component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/',
    component: homepage,
    redirect: '/homepage',
    children: [
      {
        path: 'homepage',
        // component: () => import('@/components/homepage'),
        name: 'Homepage',
        meta: { title: 'Homepage', icon: 'homepage', affix: true }
      }
    ]
  },
  {
    path: '/product',
    component: homepage,
    children: [
      {
        path: 'product',
        name: 'Product',
        meta: { title: 'Product', icon: 'product', affix: true }
      }
    ]
  },
  {
    path: '/about',
    component: homepage,
    children: [
      {
        path: 'about',
        name: 'About',
        meta: { title: 'About', icon: 'about', affix: true }
      }
    ]
  },
  {
    path: '/health',
    component: homepage,
    children: [
      {
        path: 'health',
        name: 'Health',
        meta: { title: 'Health', icon: 'health', affix: true }
      }
    ]
  },
  {
    path: '/usercenter',
    component: homepage,
    children: [
      {
        path: 'usercenter',
        name: 'UserCenter',
        meta: { title: 'UserCenter', icon: 'usercenter', affix: true }
      }
    ]
  },
  {
    path: '/contact',
    component: homepage,
    children: [
      {
        path: 'contact',
        name: 'Contact',
        meta: { title: 'Contact', icon: 'contact', affix: true }
      }
    ]
  }
  // {
  //   path: '/login',
  //   component: () => import('@/views/login/index'),
  //   hidden: true
  // },
  // {
  //   path: '/404',
  //   component: () => import('@/views/error-page/404'),
  //   hidden: true
  // },
  // {
  //   path: '/401',
  //   component: () => import('@/views/error-page/401'),
  //   hidden: true
  // },
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   children: [
  //     {
  //       path: 'dashboard',
  //       component: () => import('@/views/dashboard/index'),
  //       name: 'Dashboard',
  //       meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/documentation',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/documentation/index'),
  //       name: 'Documentation',
  //       meta: { title: 'Documentation', icon: 'documentation', affix: true }
  //     }
  //   ]
  // }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export default router

// export default new Router({
//   routes: [
//     {
//       path: '/',
//       name: 'homepage',
//       component: homepage
//     }
//   ]
// })
